<?php


namespace App\Models;


use App\User;

class ProductComment extends BaseModel
{
    public static function getPageList($where)
    {
        $list = self::getPaginate($where);
        foreach ($list['data'] as $key => &$val) {
            $user = User::find($val['id']);
            if ($user) {
                $user = $user->toArray();
            }
            $val['user'] = $user;
        }
        return $list;
    }
    
    public static function getOneByProductId($product_id)
    {
        $comment = self::where('product_id', $product_id)->orderBy('id','desc')->first();
        if ($comment) {
            $comment = $comment->toArray();
            $user = User::find($comment['user_id']);
            if ($user) {
                $comment['user'] = $user->toArray();
            }
        }
        return $comment;
    }
}